       IDENTIFICATION DIVISION.
       PROGRAM-ID.   GUARNA-TP1.
       AUTHOR.       PINEDA-ARMANDO-FACUNDO.

       ENVIRONMENT DIVISION.
	   CONFIGURATION SECTION.
	   SPECIAL-NAMES.
	       DECIMAL-POINT IS COMMA.
SEC-IO INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT FILE-CHOF ASSIGN TO DISK
                     ORGANIZATION IS LINE SEQUENTIAL
                     FILE STATUS IS WSS-FS-FILE-CHOF.
           SELECT FILE-IDX-CHOF ASSIGN TO DISK
		        ACCESS MODE IS SEQUENTIAL
				RECORD KEY IS IDX-KEY
                ORGANIZATION IS INDEXED
                FILE STATUS IS WSS-FS-FILE-IDX-CHOF.
           
SEC-DD DATA DIVISION.
       FILE SECTION.
      *****************************************
      * DECLARACION DE NOMBRES DE ARCHIVOS Y SUS REGISTROS
      *****************************************
       FD FILE-CHOF LABEL RECORD IS STANDARD
             VALUE OF FILE-ID IS "choferes.dat".
       01 REG-FILE-CHOF.
          03 CHOF-NRO-LEGAJO                PIC X(7).
          03 CHOF-FECHA-DESDE                  PIC 9(8).
          03 CHOF-FECHA-HASTA                  PIC 9(8).
          03 CHOF-TURNO               PIC X.

       FD FILE-IDX-CHOF LABEL RECORD IS STANDARD
             VALUE OF FILE-ID IS "choferes.idx".
       01 REG-FILE-IDX-CHOF.
	      03 IDX-KEY.                        
           05 IDX-NRO-LEGAJO                PIC X(7).
           05 IDX-FECHA-DESDE                  PIC 9(8).
          03 IDX-FECHA-HASTA                   PIC 9(8).
          03 IDX-TURNO                PIC X.
          
.     *----------------------------------------------------------------*
SEC-WS WORKING-STORAGE SECTION.
      *----------------------------------------------------------------*
     
      *----------------------------------------------------------------*
.     * VARIABLES GENERALES
      *----------------------------------------------------------------*
.     *----------------------------------------------------------------*
      * CONSTANTES
      *----------------------------------------------------------------*
       01 WSC-OK                       PIC X(2) VALUE '00'.
       01 WSC-EOF                      PIC X(2) VALUE '10'.
.     *----------------------------------------------------------------*
      * FILE STATUS
      *----------------------------------------------------------------*
       01 WSS-FS-FILE-CHOF               PIC X(02).
          88 WSS-88-OK-FILE-CHOF         VALUE ZEROES.
          88 WSS-88-EOF-FILE-CHOF        VALUE '10'.
       01 WSS-FS-FILE-IDX-CHOF           PIC X(02).
          88 WSS-88-OK-FILE-IDX-CHOF     VALUE ZEROES.
          88 WSS-88-EOF-FILE-IDX-CHOF    VALUE '10'.

      *************************************************
      * PROCEDURE DIVISION - AREA DE PROGRAMA 1ER NIVEL
      *************************************************
DIV-PR PROCEDURE DIVISION.
       COMIENZO.
           PERFORM 1000-INICIO 
              THRU 1000-INICIO-EXIT.
              
           PERFORM 2000-COPIA
              THRU 2000-COPIA-EXIT
			  UNTIL WSS-FS-FILE-CHOF = '10'
               
           PERFORM 9000-FIN
              THRU 9000-FIN-EXIT.
      ***************************************************************
.     *APERTURA DE LOS ARCHIVOS
      ***************************************************************
       1000-INICIO.
           DISPLAY "INICIO".
		   OPEN INPUT FILE-CHOF.
		   OPEN OUTPUT FILE-IDX-CHOF.
       1000-INICIO-EXIT.
      ***************************************************************
.     *COPIA AL INDEXADO
      ***************************************************************
       2000-COPIA.
           DISPLAY "COPIA".
		   PERFORM LECTURA THRU LECTURA-EXIT	
		   MOVE REG-FILE-CHOF TO REG-FILE-IDX-CHOF.
		   IF WSS-FS-FILE-CHOF = '00' THEN
               DISPLAY 'KEY: ' IDX-KEY		   
		       WRITE REG-FILE-IDX-CHOF
		   END-IF.
           DISPLAY "NO COPIA".
       2000-COPIA-EXIT.
	   
	   
.     *LECTURA
       LECTURA.
		   READ FILE-CHOF AT END CONTINUE.
		   EVALUATE TRUE
		       WHEN WSS-88-OK-FILE-CHOF 
			        DISPLAY 'UN CHOF LEIDO'
		       WHEN WSS-88-EOF-FILE-CHOF
                    CONTINUE
               WHEN OTHER
                    DISPLAY 'ERROR ' WSS-FS-FILE-CHOF
                    STOP RUN
		   END-EVALUATE.
	   LECTURA-EXIT.
	       EXIT.
      ***************************************************************
.     *CIERRE DE TODOS LOS ARCHIVOS
      ***************************************************************
       9000-FIN.
	       CLOSE FILE-CHOF.
	       CLOSE FILE-IDX-CHOF.
           DISPLAY "FIN DE PROGRAMA GUARNA-TP1".
           STOP RUN.
       9000-FIN-EXIT.
	       EXIT.